Statusbar: Remove matching messages before popping
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Wed, 12 Feb 2014 15:56:11 +0000 (15:56 +0000)
committerBenjamin Otte <otte@redhat.com>
Thu, 14 Aug 2014 17:52:59 +0000 (19:52 +0200)
gtk_statusbar_remove_all() was popping the top message if its
context_id matched before removing other matching messages from the
stack. This meant that if the context_id of the second top message
matched it was still displayed when the top message was popped and
then removed from the list of messages without updating the display.
Fix this by removing all the matching messages below the top one
before popping it if it matches.

https://bugzilla.gnome.org/show_bug.cgi?id=724281

gtk/gtkstatusbar.c

index a49457f0f33d336ab90815a980911ca9ac2fd8fc..18f974e6bb813b1ae70c7e71e323d7fe29c9cde0 100644 (file)
@@ -456,21 +456,13 @@ gtk_statusbar_remove_all (GtkStatusbar *statusbar,
   if (priv->messages == NULL)
     return;
 
-  msg = priv->messages->data;
-
-  /* care about signal emission if the topmost item is removed */
-  if (msg->context_id == context_id)
-    {
-      gtk_statusbar_pop (statusbar, context_id);
-
-      prev = NULL;
-      list = priv->messages;
-    }
-  else
-    {
-      prev = priv->messages;
-      list = prev->next;
-    }
+  /* We special-case the topmost message at the bottom of this
+   * function:
+   * If we need to pop it, we have to update various state and we want
+   * an up-to-date list of remaining messages in that case.
+   */
+  prev = priv->messages;
+  list = prev->next;
 
   while (list != NULL)
     {
@@ -478,21 +470,12 @@ gtk_statusbar_remove_all (GtkStatusbar *statusbar,
 
       if (msg->context_id == context_id)
         {
-          if (prev == NULL)
-            priv->messages = list->next;
-          else
-            prev->next = list->next;
+          prev->next = list->next;
 
           gtk_statusbar_msg_free (msg);
           g_slist_free_1 (list);
 
-          if (prev == NULL)
-            prev = priv->messages;
-
-          if (prev)
-            list = prev->next;
-          else
-            list = NULL;
+          list = prev->next;
         }
       else
         {
@@ -500,6 +483,13 @@ gtk_statusbar_remove_all (GtkStatusbar *statusbar,
           list = prev->next;
         }
     }
+
+  /* Treat topmost message here */
+  msg = priv->messages->data;
+  if (msg->context_id == context_id)
+    {
+      gtk_statusbar_pop (statusbar, context_id);
+    }
 }
 
 /**